<template>
  <div class='container'>
    <el-card class="filter-container" shadow="never">
      <!--<div>
        <i class="el-icon-search"></i>
        <span>筛选搜索</span>
        <el-button
          style="float:right"
          type="primary"
          size="small"
          @click="search_button()">
          查询搜索
        </el-button>
        <el-button
          style="float:right;margin-right: 15px"
          size="small"
          @click="reset_button()">
          重置
        </el-button>
      </div>
      <div style="margin-top: 15px">
        <el-form :inline="true"  size="small" label-width="140px">
          <el-form-item label="输入搜索：">
            <el-input  class="input-width" v-model="shop_id_value" placeholder="门店id号" clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div style="margin-top: 15px">
        <el-form :inline="true"  size="small" label-width="140px">
          <el-form-item label="输入搜索：">
            <el-input  class="input-width" v-model="uid_value" placeholder="门店id号" clearable></el-input>
          </el-form-item>
        </el-form>
      </div>-->
    </el-card>
    <!-- <el-card class="operate-container" shadow="never">
       <i class="el-icon-tickets"></i>
       <span>佣金列表</span>
       <el-button size="mini" class="btn-add" @click="multiple_delete_button()" style="margin-left: 20px; float:right" icon='el-icon-delete' type="danger">批量删除</el-button>
       <el-button size="mini" class="btn-add" @click="add_button()" style="margin-left: 20px; float:right" icon='el-icon-plus' type="primary">添加</el-button>
     </el-card>-->
    <div class='table-container'>
      <el-table
        class='m-30-t'
        :data="order_share_log_list"
        fit
        stripe
        border
        v-loading="listLoading"
        highlight-current-row>
        <el-table-column type="selection" ></el-table-column>
        <el-table-column
          prop="id"
          label="id"
          align="left"
          width='100'>
        </el-table-column>
        <el-table-column
          label="用户id"
          align="center"
        >
          <template slot-scope="scope">
            <span @click="go_user_detail(scope.row.uid)">{{scope.row.true_name}}</span>
          </template>
        </el-table-column>
        <el-table-column label="源订单号" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.sourceId}}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="amount"
          label="佣金金额"
          align="center">
        </el-table-column>
        <el-table-column
          prop="event"
          label="event"
          align="center">
          <template slot-scope="scope">
            <span>{{scope.row.event}}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="status"
          label="金额"
          align="center">
          <template slot-scope="scope">
            <span>{{scope.row.amountLog}}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="time"
          label="创建时间"
          width="200px"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          width="300px">
          <template slot-scope="scope">
            <el-button size="small" type="warning" @click="detail_button(scope.row.id)">详情</el-button>
            <!--<el-button  size="small" type="danger" @click="delete_button(scope.row.id)">删除</el-button>
            <el-button  size="small" type="success" @click="edit_button(scope.$index, scope.row)">编辑</el-button>-->
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container m-50-t m-50-b">
      <span></span>
      <el-pagination
        background
        @size-change="size_change"
        @current-change="current_change"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="page_num"
        :page-size="page_size"
        :page-sizes="page_sizes"
        :total="total">
      </el-pagination>
    </div>
    <el-dialog
      title="佣金详情"
      width="50%"
      :visible.sync="detail_dialog_visible">
      <div>
        <span class="title">佣金名称：</span>
        <span class="m-10-l ">{{detail_data.event}}</span>
      </div>
      <div class=' m-30-t'>
        <span class="title">佣金金额：</span>
        <span class="m-10-l  ">{{detail_data.amount}}</span>
      </div>
      <div class=' m-30-t'>
        <span class="title">订单号：</span>
        <span class="m-10-l  ">{{detail_data.sourceId}}</span>
      </div>
      <div class=' m-30-t'>
        <span class="title">创建日期：</span>
        <span class="m-10-l  ">{{detail_data.time}}</span>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="detail_dialog_visible = false" size="small">取 消</el-button>
        <el-button @click="detail_dialog_visible = false" type="primary" size="small">确 定</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import order_share_log_request from "@/api/order_share_log_request"
import user_finance_request from "@/api/user_finance_request"
export default {
  name: 'order_share_log',
  data() {
    return {
      base: 'http://pai.xtyxmall.com/data/',
      ctype_list: ['','支出','收入','分销提成','一级业务提成','二级提成','中心门店分成','区域经销商分成','门店提成',],
      status_list: ['','处理中','已完成'],
      delete_list: [],
      detail_data: {},
      order_share_log_list: [],
      dialog_visible: false,
      isEdit: false,
      search_value: '',
      page_num: 1,
      page_size: 10,
      page_sizes: [10,20,50],
      total: null,
      name: '',
      order_share_log_no: '',
      birthday: '',
      create_time: '',
      detail_dialog_visible: false,
      listLoading: false,
      keyword: '',
      uid_value: '',
      shop_value: '',
      current_size: 10,
      current_page: 1,
      target_id: '',
    }
  },
  created() {
    this.uid_value = this.$route.query.uid
    this.shop_id_value = this.$route.query.shop_id
    this.get_list()
  },
  mounted() {

  },
  methods: {
    chosen_option(id_list) {
      this.delete_list = id_list
    },
    all_options(id_list) {
      this.delete_list = id_list
    },
    multiple_delete_button() {
      this.$confirm('是否要进行批量删除操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        for (let item of this.delete_list) {
          order_share_log_request.delete_order_share_log({id: item.id}, res=> {
            this.get_list()
          })
        }
        this.delete_list = []
      }).catch(err=>err)
    },
    // 搜索
    search_button() {
      this.current_page = 1
      this.keyword = this.keyword_value
      this.get_list()
    },
    // 重置
    reset_button() {
      this.keyword = ''
      this.keyword_value= ''
      this.get_list()
    },
    // 添加
    add_button() {
      this.$router.push({path:'/QA/order_share_log_add'});
    },
    // 确认
    // 删除
    delete_button(id) {
      this.$confirm('是否要进行删除操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let params = {
          id
        }
        order_share_log_request.delete_order_share_log(params, res=> {
          this.get_list()
        })
      }).catch(err=>err)
    },
    // 编辑
    edit_button(index, item) {
      // this.dialog_visible = true;
      // this.isEdit = true;
      // this.name = item.name
      // this.create_time = item.create_time
      // this.order_share_log_no = item.order_share_log_no
      // this.birthday = item.birthday
      // this.target_id = item.id
      this.$router.push({path: '/QA/order_share_log_edit', query:{id: item.id, gid: item.order_share_log_no}})
    },
    // 详情
    detail_button(id) {
      user_finance_request.user_account_log_detail({id}, res=> {
        this.detail_data = res.data
      })
      this.detail_dialog_visible = true
    },
    size_change(current_size) {
      this.current_size = current_size
      this.get_list()
    },
    current_change(current_page) {
      this.current_page = current_page
      this.get_list()
    },
    // filter_list() {
    //   order_share_log_request.order_share_log_list({pageSize: this.current_size, key: this.keyword, page: this.search_page}, res=> {
    //     this.order_share_log_list = res.data
    //     this.total = res.data.length
    //   })
    // },
    get_list() {
      this.listLoading = true;
      const params = {
        pageSize: this.current_size,
        limit: this.current_size,
        page: this.current_page,
        // shop_id: this.shop_id_value,
        // uid: this.uid_value
      }
      user_finance_request.user_account_log_list(params, res => {
        this.listLoading = false
        this.order_share_log_list = res.data
        this.total = res.count
      })
    },
    go_user_detail(id) {
      this.$router.push({path: '/user/user_detail', query:{id}})

    },
    go_order_detail(id) {
      this.$router.push({path: '/order/order_detail', query:{id}})

    },
    go_shop_detail(id) {
      this.$router.push({path: '/shop/shop_list_detail', query:{id}})

    },

  }
}
</script>

<style scoped>
@import "~@/styles/layout.scss";
.table-container {
  margin-left: 30px;
}
.pagination-container {
  float: right;
}

.table-item {
  height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

</style>
